#define MATH_MATRIX_SCALAR_MULT_EQU_OP( TYPE )          \
template< typename T, unsigned int R, unsigned int C >  \
Matrix<T,R,C>& operator*=( Matrix<T,R,C>& a, TYPE b ) { \
  for( unsigned int i = 0; i < R; ++i ) {               \
    for( unsigned int k = 0; k < C; ++k ) {             \
      a[i][k] *= b;                                     \
    }                                                   \
  }                                                     \
  return a;                                             \
}                                                       \

#define MATH_MATRIX_SCALAR_DIV_EQU_OP( TYPE )           \
template< typename T, unsigned int R, unsigned int C >  \
Matrix<T,R,C>& operator/=( Matrix<T,R,C>& a, TYPE b ) { \
  for( unsigned int i = 0; i < R; ++i ) {               \
    for( unsigned int k = 0; k < C; ++k ) {             \
      a[i][k] /= b;                                     \
    }                                                   \
  }                                                     \
  return a;                                             \
}                                                       \

#define MATH_MATRIX_SCALAR_MULT_OP( TYPE )                  \
template< typename T, unsigned int R, unsigned int C >      \
Matrix<T,R,C> operator*( const Matrix<T,R,C>& a, TYPE b ) { \
  Matrix<T,R,C> temp(a);                                    \
  temp *= b;                                                \
  return temp;                                              \
}                                                           \

#define MATH_MATRIX_SCALAR_DIV_OP( TYPE )                   \
template< typename T, unsigned int R, unsigned int C >      \
Matrix<T,R,C> operator/( const Matrix<T,R,C>& a, TYPE b ) { \
  Matrix<T,R,C> temp(a);                                    \
  temp /= b;                                                \
  return temp;                                              \
}                                                           \

#define MATH_SCALAR_MATRIX_MULT_OP( TYPE )                  \
template< typename T, unsigned int R, unsigned int C >      \
Matrix<T,R,C> operator*( TYPE b, const Matrix<T,R,C>& a ) { \
  Matrix<T,R,C> temp(a);                                    \
  temp *= b;                                                \
  return temp;                                              \
}                                                           \

#define MATH_APPLY_SCALER_TO_MATRIX( TYPE )    \
MATH_MATRIX_SCALAR_MULT_EQU_OP(TYPE)           \
MATH_MATRIX_SCALAR_DIV_EQU_OP(TYPE)            \
MATH_MATRIX_SCALAR_MULT_OP(TYPE)               \
MATH_MATRIX_SCALAR_DIV_OP(TYPE)                \
MATH_SCALAR_MATRIX_MULT_OP(TYPE)               \

// Defaults
MATH_APPLY_SCALER_TO_MATRIX(int)
MATH_APPLY_SCALER_TO_MATRIX(float)
MATH_APPLY_SCALER_TO_MATRIX(double)